package com.modifiertech.lineage.api;

import com.modifiertech.lineage.network.MessageDataSync;
import com.modifiertech.lineage.network.NetworkHandler;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraftforge.fml.common.FMLCommonHandler;

import java.util.Optional;

public class LineageModAccess {

    public void syncPlayerData(EntityPlayer entityPlayer, PlayerData playerData) {
        if (entityPlayer instanceof EntityPlayerMP) {
            MessageDataSync message = new MessageDataSync(playerData);
            NetworkHandler.INSTANCE.sendTo(message, (EntityPlayerMP) entityPlayer);
        }
    }

    /**获取服务器玩家信息
     *
     * @param entityPlayer
     * @return
     */
    public static Optional<EntityPlayerMP> getPlayerMpFromEntityPlayer(EntityPlayer entityPlayer, boolean onlyNeedFromServer){
        if(entityPlayer instanceof EntityPlayerMP){
            return Optional.of((EntityPlayerMP) entityPlayer);
        }else{
            return Optional.empty();
        }
    }
    
    //判断当前是否客户端环境
    public static boolean isClientSide() {
        return !FMLCommonHandler.instance().getEffectiveSide().isServer();
    }

}
